package com.faceye.test.service.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DynamicProxy implements InvocationHandler {

    private Object targetObject=null;

    public Object newProxy(Object targetObject){
        this.targetObject=targetObject;
        return Proxy.newProxyInstance(targetObject.getClass().getClassLoader(), targetObject.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        this.before();
        Object reflet = method.invoke(targetObject,args);
        this.after();
        return reflet;
    }

    private void before() {
        System.out.println("before");
    }
    private void after(){
        System.out.println("after");
    }
}
